package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.pojo.entity.Material;
import com.example.service.IMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * TODO
 *
 * @author wy
 * @since 2024/7/17
 */
@RestController
@RequestMapping("/material")
@Api(tags = "物资接口")
@Slf4j
public class MaterialController {

    @Autowired
    private IMaterialService iMaterialService;

    @PostMapping("/add")
    @ApiOperation("新增物资信息")
    public Result add(@RequestBody Material material) {
        iMaterialService.add(material);
        return Result.success(material);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("通过物资编号删除物资信息")
    public Result delete(@PathVariable("id") Integer id){
        iMaterialService.delete(id);
        return Result.success();
    }

    @PutMapping("/update")
    @ApiOperation("修改物资信息")
    public Result update(@RequestBody Material material){
        iMaterialService.updateById(material);
        return Result.success();
    }
    /**
     * 分页查询
     */
    @ApiOperation("分页展示物资信息列表")
    @GetMapping("/selectPage")
    public Result selectPage(Material material,
                                                @RequestParam(defaultValue = "1") Integer pageNum,
                                                @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<Material> page = iMaterialService.selectPage(material, pageNum, pageSize);
        return Result.success(page);
    }

}
